package com.bw.zg3park2212.point


import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.entity.PointEntityItem
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.R
import com.bw.zg3park2212.adpter.OrderAdpter
import com.bw.zg3park2212.adpter.TaskAdpter
import com.bw.zg3park2212.databinding.ActivityPointXiangBinding
import com.google.android.material.tabs.TabLayout

import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/PointXiangActivity")
class PointXiangActivity : BaseActivity<ActivityPointXiangBinding,PointViewModel>() {
    @Autowired
    lateinit var pointid:PointEntityItem
    lateinit var list1Adpter: List1Adpter
    lateinit var taskAdpter: TaskAdpter
    lateinit var orderAdpter: OrderAdpter
    var list1= mutableListOf<String>(
        "1 绿地是否需要修剪",
        "2 现场是否有垃圾",
        "3 是否有安全隐患",
        "4 设施是否有损坏")
    override fun intitView() {
        ARouter.getInstance().inject(this)
        viewmodel.getpointxiang(pointid.id)
        binding.tab.addTab(binding.tab.newTab().setText("巡检标准"))
        binding.tab.addTab(binding.tab.newTab().setText("巡检记录"))
        binding.tab.addTab(binding.tab.newTab().setText("工单记录"))
        list1Adpter= List1Adpter()
        taskAdpter= TaskAdpter()
        orderAdpter= OrderAdpter()
        binding.rv.layoutManager=LinearLayoutManager(this)
        binding.rv.adapter=list1Adpter
        viewmodel.gettask()
        viewmodel.getorder()
        binding.tab.addOnTabSelectedListener(object:TabLayout.OnTabSelectedListener{
            override fun onTabSelected(tab: TabLayout.Tab?) {
                when (tab?.position){
                    0->{
                        binding.rv.adapter=list1Adpter
                    }
                    1->{
                        binding.rv.adapter=taskAdpter
                    }
                    2->{
                        binding.rv.adapter=orderAdpter
                    }
                }

            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {

            }

            override fun onTabReselected(tab: TabLayout.Tab?) {

            }
        })
        list1Adpter.addData(list1)
    }

    override fun intitData() {
        viewmodel.pointxiangSuccse.observe(this){
            binding.pointxiangPointName.text="项目名称: "+it.pointName
            binding.pointxiangProjectId.text="点位名称: "+it.projectId
            binding.pointxiangPointLocation.text="点位位置: "+it.pointLocation
            if(it.patrolType=="保洁巡检"){
                binding.pointxiangPatrolType.setBackgroundResource(R.drawable.bg_kongxian)
                binding.pointxiangPatrolType.setTextColor(this.getColor(R.color.color_kongxian))
                binding.pointxiangPatrolType.setText("保洁巡检")
            }else if(it.patrolType=="安防巡检"){
                binding.pointxiangPatrolType.setBackgroundResource(R.drawable.bg_zganyong)
                binding.pointxiangPatrolType.setTextColor(this.getColor(R.color.color_zhanyong))
                binding.pointxiangPatrolType.setText("安防巡检")
            }else if(it.patrolType=="日常巡检"){
                binding.pointxiangPatrolType.setBackgroundResource(R.drawable.bg_weihu)
                binding.pointxiangPatrolType.setTextColor(this.getColor(R.color.color_weihu))
                binding.pointxiangPatrolType.setText("日常巡检")
            }else{
                binding.pointxiangPatrolType.setBackgroundResource(R.drawable.bg_hui)
                binding.pointxiangPatrolType.setTextColor(this.getColor(R.color.color_hui))
                binding.pointxiangPatrolType.setText("家居巡检")
            }
        }
        viewmodel.taskSuccse.observe(this){
            taskAdpter.data.clear()
            taskAdpter.addData(it)
            taskAdpter.notifyDataSetChanged()
        }
        viewmodel.orderSucsse.observe(this){
            orderAdpter.data.clear()
            orderAdpter.addData(it)
            orderAdpter.notifyDataSetChanged()
        }

    }

}